





//
//  NQiuzhiInfoDetailVC.m
//  nncloud
//
//  Created by macfai on 2018/11/29.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NQiuzhiInfoDetailVC.h"
#import "NZhaopinCell.h"
#import "NMiaoshuCell.h"
#import "NEditDeleteView.h"
#import "NEditInfoViewController.h"

@interface NQiuzhiInfoDetailVC ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@property(nonatomic,strong)NSArray *titleArray;
@property(nonatomic,strong)NSArray *infoArray;

@property (nonatomic,copy)NSString *selfIntroMsg;
@property (nonatomic,copy)NSString *telephone;
@property (nonatomic,copy)NSString *email;

@property (nonatomic,copy)NSString *resumeId;


@end

@implementation NQiuzhiInfoDetailVC

//求职详情
#define cellIdentifier @"zhaopin"
#define miaoshuCell @"miaoshu"
#define SectionHeaderHeight  10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        //        _tableView.rowHeight = 115.f;
        _tableView.separatorStyle = 0;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NZhaopinCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        [_tableView registerNib:[UINib nibWithNibName:@"NMiaoshuCell" bundle:nil] forCellReuseIdentifier:miaoshuCell];
        _tableView.showsVerticalScrollIndicator = NO;
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    self.dataArray = [NSMutableArray array];
    [self.navigationItem setItemWithTitle:@"求职者信息" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    
    self.titleArray = @[@"性别",@"生日",@"婚姻状况",@"身高(单位:cm)",@"体重(单位:kg)",@"居住地",@"学历",@"毕业院校",@"专业",@"工作性质",@"工作经验",@"行业意向",@"职位意向",@"专业技能",@"期望薪资",@"求职状态",];
//    self.infoArray = @[@"男",@"1990-9-8",@"已婚",@"175",@"160",@"北京",@"本科",@"北京大学",@"英语",@"民营",@"5年",@"行业意向",@"职位意向",@"高级开发",@"25",@"寻求机会",];
    [self.view addSubview:self.tableView];
    
    //个人端才能进行信息编辑
    if ([[NUserModel shareInstance].userInfoType integerValue]==0) {
         [self addFooter];
    }
   
    [self loadData];
    // Do any additional setup after loading the view.
}

- (void)addFooter {
    WeakStament(ws);
     NEditDeleteView *footer = [[[NSBundle mainBundle] loadNibNamed:@"NEditDeleteView" owner:self options:nil] lastObject];
    footer.editAction = ^(UIButton * _Nonnull btn) {
        YYLog(@"点击了编辑");
        [ws editInfoData];
    };
    footer.deleteAction = ^(UIButton * _Nonnull btn) {
        YYLog(@"点击了delete");
        [ws alertView];
//        [ws deleteData];
    };
    self.tableView.tableFooterView = footer;
}

- (void)alertView {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                    message:@"确认删除？"
                                                   delegate:self
                                          cancelButtonTitle:@"取消"
                                          otherButtonTitles:@"确认",nil];
    [alert show];
}

#pragma mark - alertView  delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
         [self deleteData];
    }else{
        
    }
}

///编辑信息
- (void)editInfoData{
    NEditInfoViewController *edit = [NEditInfoViewController new];
    edit.infoArr = [self.infoArray copy];
    edit.email = self.email;
    edit.tele = self.telephone;
    edit.selfInfo = self.selfIntroMsg;
    [self.navigationController pushViewController:edit animated:YES];
}
///删除信息
- (void)deleteData{
    
    NSDictionary *dic = @{@"resumeId":self.resumeId};
    
//    [NNetworkClient postRequestWithBaseUrl:kResumeDeleteUrl setParameters:dic success:^(id responseObject) {
//        YYLog(@"%@",responseObject);
//        if ([responseObject[@"code"]integerValue]==0) {
//
//            [AFToast showText:@"删除成功"];
//            [self.navigationController popViewControllerAnimated:YES];
//
//        }else{
//
//            [AFToast showText:responseObject[@"msg"]];
//
//        }
//    } fail:^(NSError *error) {
//
//    } delegater:nil];
    [[NNRCNetRequest manager]postWithUrl:kResumeDeleteUrl params:dic success:^(id result) {
        YYLog(@"%@",result);
        if ([result[@"code"]integerValue]==0) {

            [AFToast showText:@"删除成功"];
            [self.navigationController popViewControllerAnimated:YES];

        }else{

            [AFToast showText:result[@"msg"]];

        }
    } failure:^(id failure) {
         YYLog(@"%@",failure);
    }];
    
}
#pragma mark - 初始数据
- (void)loadData{
    ///如果是从个人求职进来，而且已经添加过个人信息，直接根据用户id 拿求职者信息
    NSDictionary *dic = @{@"resumeUserId":self.qiuzhiId?:[NUserModel shareInstance].userInfoId};
    [[NNRCNetRequest manager]getWithUrl:kQiuzhiDetailUrl params:dic success:^(id result) {
        
        YYLog(@"%@",result);
        WeakStament(ws);
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            NSDictionary *dict = result[@"page"];
            NQiuzhiModel *model = [NQiuzhiModel mj_objectWithKeyValues:[dict deleteNull]];
            [ws.dataArray addObject:model];
            [ws formDataWithModel:model];
            [ws.tableView reloadData];
        }else{
            [AFToast showText:result[@"msg"]];
        }
        
    } failure:^(id failure) {
        
    }];
}

- (void)formDataWithModel:(NQiuzhiModel *)model {
    
    self.resumeId = model.resumeId;
    NSString *male = @"男";
    NSString *birth = model.resumeBirthday;
    //(0:已婚，1:未婚，2:其他)
    NSString *marriage;
    if ([model.resumeMarriage integerValue]==0) {
        marriage = @"已婚";
    }else if ([model.resumeMarriage integerValue]==1){
        marriage = @"未婚";
    }else{
        marriage = @"其他";
    }
    NSString *height = [NSString stringWithFormat:@"%@",model.resumeHeight];
    NSString *weight = [NSString stringWithFormat:@"%@",model.resumeBodyWeight];
    
    NSString *area =  model.resumePlace;
    //(0:初中，1:高中，2:中专，3:大专，4:本科，5:硕士，6:博士)
    NSString *xueli = [self education:model.resumeEducation];
    NSString *school = model.resumeSchool;
    NSString *professtino = model.resumeProfession;
    
    //0:不限，1:全职，2:兼职，3:实习
    NSString *workXingzhi;
    if ([model.resumeWorkNature integerValue]==0) {
        workXingzhi = @"不限";
    }else if ([model.resumeWorkNature integerValue]==1){
        workXingzhi = @"全职";
    }else if([model.resumeWorkNature integerValue]==2){
        workXingzhi = @"兼职";
    }else{
        workXingzhi = @"实习";
    }
    NSString *experince = [NSString stringWithFormat:@"%@年",model.resumeWorkExperience];
    
    NSString *hangyeyixiang = [self industryIntention:model.resumeIndustryIntention];
    
    NSString *zhiweiyixiang  = [self positionIntention:model.resumeJobIntention];
    
    NSString *jineng = model.resumeProfessionalSkill;
    NSString *salary = model.resumeSalary;
    
    //0:目前正在找工作,1:观望有好机会会考虑,2:目前不想换工作
    NSString *status;
    if ([model.resumeJobStatus integerValue]==0) {
        status = @"目前正在找工作";
    }else if ([model.resumeJobStatus integerValue]==1){
        status = @"观望有好机会会考虑";
    }else{
        status = @"目前不想换工作";
    }
    
    
    self.infoArray = @[male,birth,marriage,height,weight,area,xueli,school,professtino,workXingzhi,experince,hangyeyixiang,zhiweiyixiang,jineng,salary,status,];
    YYLog(@"%@",self.infoArray);
    
}

//学历  (0:初中，1:高中，2:中专，3:大专，4:本科，5:硕士，6:博士)
-(NSString *)education:(NSString *)type{
    
    switch ([type integerValue]) {
        case 0:
            return @"初中";
            break;
        case 1:
            return @"高中";
            break;
        case 2:
            return @"中专";
            break;
        case 3:
            return @"大专";
            break;
        case 4:
            return @"本科";
            break;
        case 5:
            return @"硕士";
            break;
        case 6:
            return @"博士";
            break;
            
        default:
            break;
    }
    return @"";
}

//行业意向  0:不限，1:机械装备制造，2:电子信息，3:铝深加工，4:食品加工，5:生物制药，6:清洁能源，7:其他行业
-(NSString *)industryIntention:(NSString *)type{
    
    switch ([type integerValue]) {
        case 0:
            return @"不限";
            break;
        case 1:
            return @"机械装备制造";
            break;
        case 2:
            return @"电子信息";
            break;
        case 3:
            return @"铝深加工";
            break;
        case 4:
            return @"食品加工";
            break;
        case 5:
            return @"生物制药";
            break;
        case 6:
            return @"清洁能源";
            break;
        case 7:
            return @"其他行业";
            break;
            
        default:
            break;
    }
    return @"";
}

//职位意向 0:不限，1:经营管理类，2:行政/人事/后勤类，3:财务/税务/审计类，4:生产制造/工工管理类，5:市场/销售类，6:客服/计算机服务类，7:计算机/互联网类，8:科研/咨询类，9:证券/金融/投资类，10:其他类
-(NSString *)positionIntention:(NSString *)type{
    switch ([type integerValue]) {
        case 0:
            return @"不限";
            break;
        case 1:
            return @"经营管理类";
            break;
        case 2:
            return @"行政/人事/后勤类";
            break;
        case 3:
            return @"财务/税务/审计类";
            break;
        case 4:
            return @"生产制造/工工管理类";
            break;
        case 5:
            return @"市场/销售类";
            break;
        case 6:
            return @"客服/计算机服务类";
            break;
        case 7:
            return @"计算机/互联网类";
            break;
        case 8:
            return @"科研/咨询类";
            break;
        case 9:
            return @"证券/金融/投资类";
            break;
        case 10:
            return @"其他";
            break;
            
        default:
            break;
    }
    return @"";
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        
        return 50.f;
        
    }else if (indexPath.section==1){
        return 45.f;
    }
    else if (indexPath.section==2){
        
        CGFloat adjustValue = 100.f;//这个值在不同的屏幕上显示会有差别,尽量给的大一点，他包括内容label的上下的margin 或者理解成padding
        return  [self getCellHeight:self.selfIntroMsg withWidth:ScreenWidth-25]+adjustValue;
    }else{
        return 135.f;
    }
    return 0.f;
    
}
#pragma mark - datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0||section==2||section==3) {
        return 1;
    }else if (section==1){
        return self.titleArray.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NQiuzhiModel *model = [self.dataArray lastObject];
    
    if (indexPath.section==0) {
        
        NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.area.hidden = YES;
        cell.date.hidden = YES;
        cell.company.hidden = YES;
        cell.salary.hidden = YES;
        cell.name.text = model.resumeName;
        cell.name.font = [UIFont boldSystemFontOfSize:15];
        cell.nameLeftMargin.constant = 25.f;
        return cell;
        
    }else if(indexPath.section==1){
        
        NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.nameLeftMargin.constant = 25.f;
        cell.area.hidden = YES;
        cell.date.hidden = YES;
        cell.company.hidden = YES;
        cell.salary.hidden = false;
        cell.name.text = self.titleArray[indexPath.row];
        cell.salary.text = self.infoArray[indexPath.row];
        return cell;
        
    }else if (indexPath.section==2){
        
        NMiaoshuCell *cell = [tableView dequeueReusableCellWithIdentifier:miaoshuCell forIndexPath:indexPath];
        cell.nameLabel.text = @"自我介绍";
        self.selfIntroMsg = model.resumeIntroduction;
        cell.detailLable.text = model.resumeIntroduction;
        return cell;
        
    }
    else{
        
        NMiaoshuCell *cell = [tableView dequeueReusableCellWithIdentifier:miaoshuCell forIndexPath:indexPath];
        
        cell.nameLabel.text = @"联系方式";
        cell.contactLabel.hidden = false;
        cell.emailLabel.hidden = false;
        cell.dianziyoujianLabel.hidden = false;
        cell.lianxishoujiLabel.hidden = false;
        cell.detailLable.hidden = YES;
        cell.contactLabel.text = model.resumePhone;
        cell.emailLabel.text = model.resumeEmail;
        self.telephone = model.resumePhone;
        self.email = model.resumeEmail;
        return cell;
    }
    
    return nil;
}

#pragma mark - 动态行高
///直接返回行高 比返回size那个少了一个步骤  推荐使用这个方法
- (CGFloat)getCellHeight:(NSString *)str withWidth:(CGFloat)width{
    CGSize size = CGSizeMake(width,MAXFLOAT); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName: kFont13};//给一个字体大小
    CGSize labelsize = [str boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine| NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    return ceil(labelsize.height);
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}


@end
